package com.gopay.solution.dao.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.solution.dao.SsApSolutionRelDAO;
import com.gopay.solution.domain.po.SsApSolutionRel;

/**
 * 账户产品与方案关系映射DAO实现
 * 
 * @SsApSolutionRelDAOImpl.java
 * @author MA HUAN
 * @2013-3-26 上午11:21:19 www.gopay.com.cn Inc.All rights reserved.
 */

@SuppressWarnings({ "unchecked", "rawtypes" })
@Repository(value="ssApSolutionRelDAO")
public class SsApSolutionRelDAOImpl extends BaseDAOImpl<SsApSolutionRel, Serializable> implements SsApSolutionRelDAO {

    @Override
    public SsApSolutionRel getByApIdAndSoluType(String prodCode, String solutionType) {
        String hql = " from SsApSolutionRel rel where rel.prodCode = :ProdCode and rel.solutionType = :SolutionType";

        Map param = new HashMap();
        param.put("ProdCode", prodCode);
        param.put("SolutionType", solutionType);

        List<SsApSolutionRel> res = super.findByHql(hql, param);

        if (res != null && res.size() > 0) {
            if (res.size() == 1)
                return res.get(0);

            // (prodCode, solutionType) should be the Pk of this table, Otherwise
            // throw Exception.
            throw new IllegalStateException("More than One Record Showed Up!, prodCode =" + prodCode + " , solutionType = "
                    + solutionType);
        }

        return null;
    }

}
